//
//  SendWeiboImageCell.m
//  share
//
//  Created by Kongho Poon on 15/3/10.
//  Copyright (c) 2015年 Jxtech. All rights reserved.
//

#import "SendWeiboImageCell.h"

@implementation SendWeiboImageCell

- (void)awakeFromNib {
  for (int i = 0; i < kSendWeiboMaxImages; i++) {
    SendWeiboImage *image = [[SendWeiboImage alloc] init];
    [self.contentView addSubview:image];
  }
}

- (void)setImageList:(NSArray *)imageList {
  _imageList = imageList;
  
  NSInteger imageCount = imageList.count;
  NSInteger count =_isSendBlog ? 1 : kSendWeiboMaxImages;

  for (int i=0; i<count; i++) {
    SendWeiboImage *cellImageView = self.contentView.subviews[i];
    CGSize screenSize = [UIScreen mainScreen].applicationFrame.size;
    
    CGFloat x ;
    if (_isSendBlog) {
      self.backgroundColor = [UIColor colorWithRed:0.867f green:0.867f blue:0.867f alpha:1.0f];
      x = screenSize.width/2 -kSubviewWH/2;
    }else{
      x = (screenSize.width - kInterval*2) / kSendWeiboMaxImages * i + GNormalMargin;
    }
    
    CGFloat y = 0;
    cellImageView.frame = CGRectMake(x, y, kSubviewWH, kSubviewWH);
    
    if (i < imageCount) {
      
      cellImageView.image = imageList[i];
      if (_isSendBlog) {
        cellImageView.index = _index;
      }else{
        cellImageView.index = i + self.row*kSendWeiboMaxImages;
      }
      
    } else {
      
      cellImageView.hidden = YES;
      if (imageCount <= count) {
        if (i == imageCount) {
          cellImageView.image = nil;
          cellImageView.hidden = NO;
        }
      }
      
    }
  }
}

- (void)setCellDelegate:(id)cellDelegate {
  _cellDelegate = cellDelegate;
  for (SendWeiboImage *cellImageView in self.contentView.subviews) {
    cellImageView.delegate = cellDelegate;
  }
}

- (void)setType:(ImageCell_Type)type {
  _type = type;
  for (SendWeiboImage *cellImageView in self.contentView.subviews) {
    cellImageView.type = type;
  }
}

@end
